package com.sise.序列化;

import java.io.*;

/**
 * 作者：idea
 * 日期：2018/6/27
 * 描述：
 */
public class SerializableTest {
    public static void writeObject() throws IOException {
        Pig p=new Pig();
        p.setId(1);
        p.setName("name");
        p.setWeight(199);
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(new File("Test.txt")));
        oos.writeObject(p);
        oos.close();
        System.out.println("写入完成！");
    }

    public static void readObject() throws IOException, ClassNotFoundException {
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream(new File("Test.txt")));
        Pig pig= (Pig) ois.readObject();
        System.out.println(pig.toString());
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        writeObject();
        readObject();
    }
}
